﻿#include "myhome.h"
#include "ui_myhome.h"
#include "mainwindow.h"
myHome::myHome(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::myHome)
{
    ui->setupUi(this);
    setWindowFlag(Qt::FramelessWindowHint);
    setAttribute(Qt::WA_TranslucentBackground);
    if (!ui->widget->layout()) {
        QVBoxLayout *layout = new QVBoxLayout(ui->widget);
        ui->widget->setLayout(layout);
    }
    ClockWidget *clockWidget = new ClockWidget(this);
    ui->widget->layout()->addWidget(clockWidget);

    QMovie *login_gif=new QMovie(":/home.gif");
    ui->label->setMovie(login_gif);
    ui->label->setStyleSheet("background:transparent");
    ui->label->setAttribute(Qt::WA_TransparentForMouseEvents);
    login_gif->start();
    QIcon app_1(":/appStore.png");
    ui->pushButton->setIcon(app_1);
    ui->pushButton->setIconSize(ui->pushButton->size());
    ui->pushButton->setStyleSheet("border:none;background:none;");
    ui->pushButton_4->setUrl(QUrl("https://www.douyin.com/"));
    ui->pushButton_5->setUrl(QUrl("https://v.qq.com/"));
    ui->pushButton_6->setUrl(QUrl("https://www.taobao.com/"));
    ui->pushButton_7->setUrl(QUrl("https://www.jd.com/"));
    ui->pushButton_8->setUrl(QUrl("https://y.qq.com/"));

}

void myHome::backWidget(QWidget *parent)
{
    back=parent;
}

void myHome::mousePressEvent(QMouseEvent *event)
{
    if (event->button() == Qt::LeftButton)
    {
        m_dragPosition = event->globalPos() - frameGeometry().topLeft();
        event->accept();
    }
}

void myHome::mouseReleaseEvent(QMouseEvent *event)
{
    if (event->button() == Qt::LeftButton)
    {
        event->accept();
    }
}

void myHome::mouseMoveEvent(QMouseEvent *event)
{
    if (event->buttons() & Qt::LeftButton)
    {
        move(event->globalPos() - m_dragPosition);
        event->accept();
    }
}


myHome::~myHome()
{
    delete ui;
}

void myHome::on_pushButton_clicked()
{
    if(store==nullptr)
    {
        store=new appStore;
    }
    store->backWidget(this);
    store->show();
    this->hide();
}

void myHome::on_pushButton_2_clicked()
{
    if(!ui->pushButton_2->icon().isNull())
    {
        MainWindow *first=static_cast<MainWindow*>(back);
        first->player->pause();
        if(pMusic==nullptr)
        {
            pMusic=new musicWindow;
        }
        pMusic->backWidget(this);
        pMusic->show();
        this->hide();
    }
    else
    {
        qDebug("请先安装软件");
    }
}

void myHome::on_pushButton_3_clicked()
{
    if(!ui->pushButton_3->icon().isNull())
    {
        if(weather==nullptr)
        {
            weather=new weatherApp;
        }
        weather->backWidget(this);
        weather->show();
        this->hide();
    }
    else
    {
        qDebug("请先安装软件");
    }
}
